package osSRC.fit;
import osSRC.Format;

import java.util.Scanner;

public class Main {
	static Scanner scanner=new Scanner(System.in);
	static String[] modes={"1.request new memory","2.return memory","0.exit"};
	static String length=
			"""
 Please choose whether to accept default memory length:
 0:\t\t\t\t\tdefault\t("""+ Memory.DEFAULT_MEMORY_LENGTH+"K)\nAny number else:\tcustom\t(K)";

	public static void main(String[] args) {
		int address,memoryLength,lengthChoice;
		Memory memory;
		lengthChoice=Format.getInt(length, scanner);
		if (lengthChoice == 0)	memory = new Memory();
		else 					memory = new Memory(Math.abs(lengthChoice));
		System.out.println("Memory initialized");

		while (true){
			switch (Format.selectMenu(modes,scanner)){
				case 2:
					memory.showAreas(false);
					address=Format.getInt("Please enter address",scanner);
					memoryLength=Format.getInt(
							"Please enter size (0 to exit)",scanner);
					if(memoryLength==0)break;
					if(memory.free(address,memoryLength))
							System.out.println("success");
					else	System.out.println("fail");
					break;
				case 1:
					memory.requestArea();
					break;
				case 0:
					System.out.println("Welcome to use again");
					return;
			}
		}
	}
}

